﻿/***************************************************************
 * 开发人员：网魂小兵@http://www.mozlite.com
 * 
 * 目标标本：4.0.30319.239
 * 
 * 最后修改：2011/12/6 11:12:59
 * ************************************************************/
namespace Mozlite.Web.UI.Areas.ControlPanel.Controllers
{
    using System;
    using System.Linq;
    using System.Text;
    using System.Collections.Generic;
    using System.Web.Mvc;
    using Mozlite.Common;

    /// <summary>
    /// 论坛控制器。
    /// </summary>
    public class ForumController : ControlPanelBaseController
    {
        public ActionResult SettingsView() {
            return View(DiscussApplication.Current.Configuration);
        }

        [HttpPost]
        public ActionResult SettingsView(DiscussConfiguration model, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                model.ApplicationID = DiscussApplication.Current.ApplicationID;
                if (Applications.SaveConfiguration<DiscussConfiguration>(model))
                    SetResourceStatus("ConfigurationBase.Save.Success");
                else
                    SetResourceStatus("ConfigurationBase.Save.Error", true);
            }
            return View(DiscussApplication.Current.Configuration);
        }

        public ActionResult PermissionSchemaView() {
            return View(Permissions.LoadPermissionSchemas<ForumPermission>().Values);
        }

        [HttpPost]
        public JsonResult PermissionSchemaView(FormCollection form)
        {
            switch (form.GetAction())
            {
                case HttpAction.Delete:
                    {
                        Guid guid = form.Get<Guid>("did", Guid.Empty);
                        if (guid != Guid.Empty)
                        {
                            if (Permissions.DeletePermissionSchema<ForumPermission>(guid))
                                return Json(new { message = Local("ForumPermissionSchema.Delete.Success"), status = true });
                            else
                                return Json(new { message = Local("ForumPermissionSchema.Delete.Error") });
                        }
                    }
                    break;
            }
            return Json(null);
        }

        public ActionResult ForumsView() {
            return View(Forums.LoadForums().Values);
        }

        public ActionResult NewForumView() {
            var forum = Forums.GetForum(this.Get<int>("id"));
            if (forum == null)
                forum = new Forum();
            return View(forum);
        }
    }
}